#include <string>

#include "schedule.h"
#include "coursesection.h"
using namespace std;

Schedule::Schedule()
{

}

Schedule::~Schedule()
{

}

Schedule::Schedule(const vector<CourseSection>& coursesRef){
	courses = coursesRef;
}

vector< CourseSection > Schedule::getCourses()
{
	return courses;
}
void Schedule::addCourse( CourseSection newCourse)
{
	courses.insert(courses.begin(), newCourse);	
}
void Schedule::removeCourse(const std::string& courseID)
{
	
}

std::ostream& operator<<(std::ostream& output, Schedule& s)
{
	vector<CourseSection> courseList = s.getCourses();
	vector<CourseSection>::iterator it;

	for(it = courseList.begin(); it != courseList.end(); ++it){
		if(it != courseList.begin())
			output << ", ";
		output << it->getCourse().lock().get()->getCourseID() << " - ";
		
		string IDs = it->getID();
		boost::weak_ptr<CourseSection> r = it->getParent();
		while(r.use_count() != 0){
            IDs.insert(IDs.begin(), ' ');
			IDs.insert(0, r.lock().get()->getID()); 
            r = it->getParent();
			if(static_cast<int>(r.lock().get()->getType()) == 1) // lecture
			{ break; }
        }
		output << IDs;
	}

	return output;
}
